package org.exia.minisig.model.database;

/**
* ItineraryDAO
* @version0.0
* @date 31/01/2013
*/

import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

import org.exia.minisig.application.LogFile;
import org.exia.minisig.application.Utils;
 
public class Database {
	//VAR
    private String DBPath;
    protected Connection connection = null;
	private Statement statement = null;
	//CONSTRUCTOR
    public Database() {
    	String f = Utils.applicationFolder();
        this.DBPath = f + "MiniSIG.sqlite";
        File bdd = new File(f + "MiniSIG.sqlite");
        if (! bdd.exists() ) {
        	LogFile.setEntry("ERREUR BASE DE DONNEE ABSENTE !");
        }
    }
    //METHODE
    public void connect() {
        try {
        	Class.forName("org.sqlite.JDBC");
            connection = DriverManager.getConnection("jdbc:sqlite:" + DBPath);
            statement = connection.createStatement();
        } catch (ClassNotFoundException notFoundException) {
            notFoundException.printStackTrace();
            LogFile.setEntry("Erreur de connexion" + notFoundException.getCause());
        } catch (SQLException sqlException) {
        	LogFile.setEntry("Erreur de connexion" + sqlException.getCause());          
        }
    }
    public void close(){
    	  try {
              connection.close();
              statement.close();
          } catch (SQLException e) {
              e.printStackTrace();
          }
    }
}